#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_twophotb.info <<'%EOF%'
   cc_rsp_twophotb
   ---------------
   Molecule:         HF in C2
   Wave Function:    CC2 / 6-31G**
   Test Purpose:     Finite difference on one-photon transition moments
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_twophotb.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    1  Y  X      1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_twophotb.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CC2
.FIELD
 0.001
 XDIPLEN
.NSYM
 2
.THRENR
 1.0d-8
.THRLEQ
 1.0d-8
*CCEXCI
.NCCEXCI
 0 4 
.THREXC
 1.0d-7
*CCLRSD
.DIPOLE
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_twophotb.check
cat >>cc_rsp_twophotb.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-100.008919(8|9)." | wc -l`
CRIT2=`$GREP "Total MP2   energy:                  \-100.193662(5|6)." $log | wc -l`
CRIT3=`$GREP "Total CC2   energy:                  \-100.194687(8|9)." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[1]=5
ERROR[1]="ENERGIES NOT CORRECT"


# CC2 excitation energies
CRIT1=`$GREP "\^1A.  \|    1   \|     ( |0)\.396682.  \|      10\.7942.  \|     87061\....  \|  96\.73" $log | wc -l`
CRIT2=`$GREP "\^1A.  \|    2   \|     1\.090983.  \|      29\.6871.  \|    239443\....  \|  96\.14" $log | wc -l`
CRIT5=`$GREP "\^1A.  \|    3   \|     1\.501583.  \|      40\.8601.  \|    329559\....  \|  99\.21" $log | wc -l`
CRIT6=`$GREP "\^1A.  \|    4   \|     1\.518328.  \|      41\.3158.  \|    333234\....  \|  99\.13" $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT5 \+ $CRIT6`
CTRL[2]=4
ERROR[2]="CC2 EXCITATION ENERGIES NOT CORRECT"

# CC2 onephoton transition moments:
CRIT1=`$GREP "\^1A.  \|    1   \|        ( |0)\.052101.      \|      ( |0)\.013778.       \|    Y " $log | wc -l`
CRIT2=`$GREP "\^1A.  \|    2   \|        ( |0)\.075966.      \|      ( |0)\.055252.       \|    Y " $log | wc -l`
CRIT3=`$GREP "\^1A.  \|    3   \|        ( |0)\.000000.      \|      ( |0)\.000000.       \|    \- " $log | wc -l`
CRIT5=`$GREP "\^1A.  \|    4   \|        ( |0)\.000000.      \|      ( |0)\.000000.       \|    Y " $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT5`
CTRL[3]=4
ERROR[3]="CC2 ONEPHOTON TRANSITON MOMENTS NOT CORRECT"


PASSED=1
for i in 1 2 3
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
